define(function(require, exports, module) {
    'use strict';

    var $ = require('jquery');
    var linkageTab = require('plugins/linkage-tab');
    var validate = require('plugins/validate/validate.method');
    require('plugins/validate/validate');
    require('plugins/serializeJSON');
    var io = require('plugins/request');
    var box = require('plugins/box/box');
    
    $('.jSelAddr').click(function(){
        linkageTab({
            //调用多级地址的对象
            linkageBox: $('.jSelAddr'),
            // 下拉列表隐藏域的id
            selectValInput: 'f1',
            // 只存选中的value值
            selectValId: 'f2',
            // area 存文本和id的隐藏域的id
            areaId: 'areaInfo2',
            // 存最后一个值的隐藏域的id
            lastValueId: 'f4',
            //selectedData:'湖南_长沙市_芙蓉区:43_430100000000_430102000000',
            degree: 4,
            lastChangeCallBack: function(e) {
                this.hide();
            },
            onClose: function() {
                
            }
        });
    });

    $('#jForm').valid({
        when: 'submit',
        fields: {
            '#name':{
                required: true,
                message: '请填写您的姓名'
            },
            "#sex":{
                required: true,
                message: '请正确填写您的性别'
            },
            "#age":{
                required: true,
                message: '请正确填写您的年龄'
            },
            '#card':{
                required: true,
                message: '请正确填写您的身份证号',
                test: validate.card
            }
        },
        submitButton: '.jSubmit',
        errorTemplate: function(error){
            return $('<span class="error-tips">'+error.message+'</span>');
        },
        happy: function(){
            var json = $('#jForm').serializeJSON();
            var $dom = $('#jSubmit');
            if($dom.hasClass('disabled')){
                return false;
            }
            $dom.addClass('disabled');
            io.post('', json, function(rst){
                box.tips(rst.data.msg);
                setTimeout(function(){
                    window.location.href = rst.data.url;
                }, 3000);
                $dom.removeClass('disabled');
            }, function(rst){
                box.error(rst.msg);
                $dom.removeClass('disabled');
            });
        }
    });

    $('#jForm').on('submit', function(){
        return false;
    });

});
